package com.zhudi.develop_demo_as.utils;

public class TrafficUtil {

//    public static void getAppTrafficAndSave(int netType){
//        int uid = android.os.Process.myUid();
//        long received = TrafficStats.getUidRxBytes(uid);
//        long transmitted = TrafficStats.getUidTxBytes(uid);
//        long allTrafficSize = received + transmitted;
//        DateTrafficDao dao = MainApplication.getInstance().getDaoSession().getDateTrafficDao();
//        List<DateTraffic> result = dao.loadAll();
//        /**最后一条数据的网络类型 0表示gps 1表示wifi*/
//        int lastType = 1;
//        /**最后一条数据 */
//        DateTraffic lastDb = null;
//        /**新增加的流量 */
//        long newTraffic = 0;
//        /**数据库中全部流量之和 */
//        long dbTrafficSize = 0;
//        if (result != null && result.size() != 0){
//           lastDb = result.get(result.size() - 1);
//            for (DateTraffic model:result){
//                dbTrafficSize = dbTrafficSize + model.getTraffic();
//            }
//        }
//        newTraffic = allTrafficSize - dbTrafficSize;//新增加的流量
//        if (lastDb != null){
//            lastType = lastDb.getType();
//        }
//        ZhudiDebugLog.d("Uid总流量" + allTrafficSize + "数据库流量" + dbTrafficSize);
//        long today = ZhudiDateUtil.getToday();
//        List<DateTraffic> toDayResult = dao.queryBuilder()
//                .where(DateTrafficDao.Properties.Date.eq(today), DateTrafficDao.Properties.Type.eq(lastType))
//                .list();
//        DateTraffic newTrafficModel = new DateTraffic();
//        newTrafficModel.setDate(today);
//        newTrafficModel.setType(netType);
//        if (toDayResult != null && toDayResult.size() != 0){
//            newTraffic = newTraffic + toDayResult.get(0).getTraffic();
//            newTrafficModel.setTraffic(newTraffic);
//            newTrafficModel.setId(toDayResult.get(0).getId());
//            dao.update(newTrafficModel);
//        } else {
//            newTrafficModel.setTraffic(newTraffic);
//            dao.insert(newTrafficModel);
//        }
//    }
}
